package com.pic.mgt.action;

import com.pic.mgt.monitor.UnitMonitor;
import com.pic.mgt.monitor.UnitMonitorException;

public class UnitMonitorControlActionImpl implements UnitMonitorControlAction {
	
	private UnitMonitor businessUnitMonitor;
	private UnitMonitor messageUnitMonitor;

	@Override
	public boolean startUnitMonitor() {
		boolean isMessageUnitMonitorStartSuccessful;
		boolean isBusinessUnitMonitorStartSuccessful;
		
		try {
			this.messageUnitMonitor.startUnitMonitor();
			
			isMessageUnitMonitorStartSuccessful = true;
		} catch (UnitMonitorException e) {
			isMessageUnitMonitorStartSuccessful = false;
		}
		
		try {
			this.businessUnitMonitor.startUnitMonitor();
			
			isBusinessUnitMonitorStartSuccessful = true;
		} catch (UnitMonitorException e) {
			isBusinessUnitMonitorStartSuccessful = false;
		}
		
		return (isMessageUnitMonitorStartSuccessful && isBusinessUnitMonitorStartSuccessful);
	}

	@Override
	public boolean stopUnitMonitor() {
		this.messageUnitMonitor.stopUnitMonitor();
		
		this.businessUnitMonitor.stopUnitMonitor();
		
		return true;
	}

	public void setBusinessUnitMonitor(UnitMonitor businessUnitMonitor) {
		this.businessUnitMonitor = businessUnitMonitor;
	}

	public void setMessageUnitMonitor(UnitMonitor messageUnitMonitor) {
		this.messageUnitMonitor = messageUnitMonitor;
	}

}
